home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH7 / SRC / SHOW_APF.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-02  |  3.1 KB  |  114 lines

  1. VERSION 4.00
  2. Begin VB.Form APFForm 
  3.    Caption         =   "Show APF"
  4.    ClientHeight    =   3135
  5.    ClientLeft      =   2415
  6.    ClientTop       =   1650
  7.    ClientWidth     =   3135
  8.    Height          =   3825
  9.    Left            =   2355
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3135
  12.    ScaleWidth      =   3135
  13.    Top             =   1020
  14.    Width           =   3255
  15.    Begin VB.PictureBox Canvas 
  16.       Height          =   3135
  17.       Left            =   0
  18.       ScaleHeight     =   3075
  19.       ScaleWidth      =   3075
  20.       TabIndex        =   0
  21.       Top             =   0
  22.       Width           =   3135
  23.    End
  24.    Begin MSComDlg.CommonDialog LoadDialog 
  25.       Left            =   2760
  26.       Top             =   -120
  27.       _version        =   65536
  28.       _extentx        =   847
  29.       _extenty        =   847
  30.       _stockprops     =   0
  31.       cancelerror     =   -1  'True
  32.       dialogtitle     =   "Load File..."
  33.       filename        =   "*.APF"
  34.       filter          =   "ASCII Picture Files (*.APF)"
  35.    End
  36.    Begin VB.Menu mnuFile 
  37.       Caption         =   "&File"
  38.       Begin VB.Menu mnuFileLoad 
  39.          Caption         =   "&Load..."
  40.          Shortcut        =   ^L
  41.       End
  42.       Begin VB.Menu mnuFileSep 
  43.          Caption         =   "-"
  44.       End
  45.       Begin VB.Menu mnuFileExit 
  46.          Caption         =   "E&xit"
  47.       End
  48.    End
  49. Attribute VB_Name = "APFForm"
  50. Attribute VB_Creatable = False
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53. Dim ThePicture As ObjPicture
  54. Private Sub canvas_Paint()
  55.     If Not ThePicture Is Nothing Then _
  56.         ThePicture.Draw canvas
  57. End Sub
  58. Private Sub Form_Load()
  59.     LoadDialog.InitDir = App.Path
  60. End Sub
  61. Private Sub Form_Resize()
  62.     canvas.Move 0, 0, ScaleWidth, ScaleHeight
  63. End Sub
  64. Private Sub mnuFileExit_Click()
  65.     Unload Me
  66. End Sub
  67. Private Sub mnuFileLoad_Click()
  68. Dim fname As String
  69. Dim filenum As Integer
  70. Dim txt As String
  71. Dim xmin As Single
  72. Dim ymin As Single
  73. Dim xmax As Single
  74. Dim ymax As Single
  75.     ' Allow the user to pick a file.
  76.     On Error Resume Next
  77.     LoadDialog.filename = "*.APF"
  78.     LoadDialog.ShowOpen
  79.     If Err.Number = cdlCancel Then
  80.         Unload LoadDialog
  81.         Exit Sub
  82.     ElseIf Err.Number <> 0 Then
  83.         Unload LoadDialog
  84.         Beep
  85.         MsgBox "Error selecting file.", , vbExclamation
  86.         Exit Sub
  87.     End If
  88.     On Error GoTo 0
  89.     fname = LoadDialog.filename
  90.     LoadDialog.InitDir = Left$(fname, Len(fname) _
  91.         - Len(LoadDialog.FileTitle) - 1)
  92.     ' Clear the pictures.
  93.     canvas.Cls
  94.     Set ThePicture = Nothing
  95.     ' Open the file.
  96.     filenum = FreeFile
  97.     Open fname For Input As #filenum
  98.     ' Make sure it's an Object Picture File.
  99.     Input #filenum, txt
  100.     If txt <> "APF PICTURE" Then
  101.         Close filenum
  102.         Beep
  103.         MsgBox "Error reading file """ & fname & """.", , vbExclamation
  104.         Exit Sub
  105.     End If
  106.     ' Read the picture.
  107.     Set ThePicture = New ObjPicture
  108.     ThePicture.FileInput filenum
  109.     ' Close the file.
  110.     Close filenum
  111.     ' Refresh the display.
  112.     canvas.Refresh
  113. End Sub
  114.